package com.mz.ozy.mvp.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.DynamicsDetailBean;
import com.mz.ozy.bean.OrderDetailBean;
import com.mz.ozy.bean.UploadBean;
import com.mz.ozy.mvp.model.PostDynamicModel;
import com.mz.ozy.mvp.view.PostDynamicContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.net.RetrofitUtils;
import com.mz.ozy.utils.RxUtil;
import com.mz.ozy.utils.ToastUtils;

import org.json.JSONObject;

import java.io.File;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;


public class PostDynamicPresenter extends BasePresenterImpl<PostDynamicContract.View> implements PostDynamicContract.Presenter {

    private PostDynamicModel mPostDynamicModel;

    public PostDynamicPresenter() {
        mPostDynamicModel = new PostDynamicModel();
    }

    @Override
    public void onPostDynamic(Context context, String tid, String commentPics, String content, String reAddress) {
        mPostDynamicModel.onPostDynamic(context, tid, commentPics, content, reAddress)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.onPostDynamicSuccess();
                    }
                });
    }

    @Override
    public void queryDynamicsDetail(Context context, String did) {
        mPostDynamicModel.queryDynamicsDetail(context, did)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<DynamicsDetailBean>(mView) {

                    @Override
                    public void onSuccesss(DynamicsDetailBean result) {
                        mView.getFiendDynamicsDetail(result);
                    }
                });
    }
}
